package Z.dailyExercise.April;

public class _338比特位计数 {
    public static void main(String[] args) {
        _338比特位计数 test = new _338比特位计数();
        System.out.println(test.countBits(2));
    }

    public int[] countBits(int num) {

        int[] res = new int[num+1];
        for (int i = 0; i <= num; i++) {
            res[i] = helper(i);

        }
        return res;

    }
    public int helper(int num){

        int cnt =0;
        while (num != 0){
            num = num&(num-1);
            cnt++;
        }
        return cnt;
    }


}
